<?php
	include 'php/config.php';	
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<script src="js/utils.js"></script>
<script src="js/issue.js"></script>
<title>Open Badges - Displayer</title>
</head>
<body>
	<h1>Open Badges - Displayer</h1>
	<div>
	<p>Da questa pagina è possibile visualizzare le badge assegnate ai vari earner</p>
	</div>
		<?php
		// Connecting, selecting database
		$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DB_NAME);
		if ($mysqli->connect_errno) {
			echo "<p>Failed to connect to MySQL: " . $mysqli->connect_error . "<p>";
		} else {
			$user_query = "SELECT `email`, `userId` FROM `user`";
			$users = $mysqli->query($user_query);
			if (!$users) {
				echo "<p>Failed to run query " . $user_query . ": (" . $mysqli->errno . ") " .
						$mysqli->error . "<p>";
			}
		}
			
	?>
	<form action="php/scripts/displayer_result.php" method="post">
	<div>
	<label>E-mail earner</label>
	<select id="user" name="user">
		<option value="">Scegli un utente</option>
	<?php
		while ($row = $users->fetch_assoc()) {
			echo "<option value=" . $row['userId'] . "#" . $row['email'] . ">" .
				 $row['email'] . " </option>";
		}
		mysqli_free_result($users);		
		$mysqli->close();
	?>
	</select>
	</div>
	<input id="display" type="submit" value="Visualizza" />
	</form>
	<div>
	<p>Torna alla <a href="index.html">Home</a></p>
	</div>
</body>
</html>